//  肝功能(浏览/编辑/添加)
//  GanGongNengTableViewController.m
//  yilutongxing
//
//  Created by  Mac on 2017/5/7.
//  Copyright © 2017年 YZE. All rights reserved.
//

#import "NingxuegongnengViewController.h"
#import "DataUtils.h"
#import <QMUITips.h>

@interface NingxuegongnengViewController ()
@property (strong, nonatomic) IBOutlet UITableViewCell *cell1;
@property (strong, nonatomic) IBOutlet UITableViewCell *cell2;
@property (strong, nonatomic) IBOutlet UITableViewCell *cell3;
@property (strong, nonatomic) IBOutlet UITableViewCell *cell4;
@property (strong, nonatomic) IBOutlet UITableViewCell *cell5;
@property (retain, nonatomic) NSArray *cellArr;//存储cell供循环调用
@end

#define PLIST_GANZANG @"checknote_coagulation.plist"

@implementation NingxuegongnengViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title=@"凝血功能";
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(save)];
    
    UIImage *leftImage=[[UIImage imageNamed:@"返回"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem *leftButtonItem=[[UIBarButtonItem alloc]initWithImage:leftImage style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    self.navigationItem.leftBarButtonItem=leftButtonItem;
    
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];//隐藏多余空cell
    
    self.cellArr = @[_cell1,_cell2,_cell3,_cell4,_cell5];
    //若是浏览/修改，则填入已有内容
    if (self.data) {
        NSMutableDictionary *dataDic = _data.mj_keyValuesAdd;
        for (int i=0; i<_cellArr.count; i++) {
            UITableViewCell *cell = _cellArr[i];
            UITextField *inputbox = [cell viewWithTag:1];
            NSString *keyname = [NSString stringWithFormat:@"coagulation%d", i+1];
            inputbox.text = dataDic[keyname];
        }
    }
}

-(void)back{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)save{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    for (int i=0; i<_cellArr.count; i++) {
        NSString *key = [NSString stringWithFormat:@"coagulation%d", i+1];
        UITableViewCell *cell = _cellArr[i];
        UITextField *inputbox = [cell viewWithTag:1];
        if (inputbox && inputbox.text.length>0) {
            [dic setObject:inputbox.text forKey:key];
        }
    }
    
    if ([self.delegate respondsToSelector:@selector(backNingxuegongneng:)]) {
        [self.delegate backNingxuegongneng:dic];
        [self back];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.cellArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    return self.cellArr[indexPath.row];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}

@end
